package com.xpffly.design.visitor.demo.service;

import com.xpffly.design.visitor.demo.service.impl.Cat;
import com.xpffly.design.visitor.demo.service.impl.Dog;
import com.xpffly.design.visitor.demo.service.impl.Mouse;
import com.xpffly.design.visitor.demo.service.impl.Pig;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author: 午夜学徒
 * @Date: 2022/4/5 17:05
 * @Description：数据结构对象
 */
public class AnimalFactory {

    private List<Animal> animalList = new ArrayList<Animal>();

    /**
     * 创建数据
     */
    public void createData() {
        for (int i = 0; i < 20; i++) {
            Random random = new Random();
            int j = random.nextInt(20);
            if (j < 5) {
                animalList.add(new Cat());
            }
            if (j >= 5 && j < 10) {
                animalList.add(new Dog());
            }
            if (j >= 10 && j < 15) {
                animalList.add(new Pig());
            }
            if (j >= 15 && j < 20) {
                animalList.add(new Mouse());
            }
        }
    }

    public void action(Person person) {
        for (Animal a : animalList) {
            a.accept(person);
        }
    }
}
